<?php global $ilang; ?>
<form action="index.php" method="post" id="freq">
    <p>
        Install language: 
        <select id="language" name="installlang" onchange="$('#freq').submit();">
            <?php
            $selected = (isset($_POST['installlang']) ? $_POST['installlang'] : '');
            foreach ($languages as $language) {
                ?>
                <option value="<?php echo $language[0]; ?>" <?php echo $selected == $language[0] ? 'selected="selected"' : ''; ?>><?php echo $language[1]; ?></option>
            <?php } ?>
        </select>
        <img id="bubble0" src="resources/information.png" />
    </p>
</form>

<form action="index.php?step=2" method="post">
    <fieldset>
        <legend><?php echo $ilang['INSTALL_STEP1_CHECKING_TITLE']; ?></legend>
        <table>
            <tr>
                <td colspan="2"><?php echo $ilang['INSTALL_STEP1_DATA_FOLDER']; ?></td>
                <td style="width: 55%;">
                    <?php if ($perms['data']) { ?>
                        <span class="success"><?php echo $ilang['INSTALL_STEP1_WRITABLE']; ?></span>
                        <?php
                    } else {
                        $fail = true;
                        ?>
                        <span class="error"><?php echo $ilang['INSTALL_STEP1_WRITE_DATA_ERROR']; ?></span>
                    <?php } ?>
                </td>
            </tr>
            <tr>
                <td style="width: 5%;"></td>
                <td>/backups</td>
                <td>
                    <?php if ($perms['backups']) { ?>
                        <span class="success"><?php echo $ilang['INSTALL_STEP1_WRITABLE']; ?></span>
                        <?php
                    } else {
                        $fail = true;
                        ?>
                        <span class="error"><?php echo $ilang['INSTALL_STEP1_BACKUPS_ERROR']; ?></span>
                    <?php } ?>
                </td>
            </tr>
            <tr>
                <td></td>
                <td>/cache</td>
                <td>
                    <?php if ($perms['cache']) { ?>
                        <span class="success"><?php echo $ilang['INSTALL_STEP1_WRITABLE']; ?></span>
                        <?php
                    } else {
                        $warning = true;
                        ?>
                        <span class="warning"><?php echo $ilang['INSTALL_STEP1_CACHE_ERROR']; ?> <img id="bubble1" src="resources/information.png" /></span>
                    <?php } ?>
                </td>
            </tr>
            <tr>
                <td></td>
                <td>/languages</td>
                <td>
                    <?php if ($perms['languages']) { ?>
                        <span class="success"><?php echo $ilang['INSTALL_STEP1_WRITABLE']; ?></span>
                        <?php
                    } else {
                        $warning = true;
                        ?>
                        <span class="warning"><?php echo $ilang['INSTALL_STEP1_LANGUAGES_ERROR']; ?> <img id="bubble2" src="resources/information.png" /></span>
                    <?php } ?>
                </td>
            </tr>
            <tr>
                <td></td>
                <td>/logs</td>
                <td>
                    <?php if ($perms['logs']) { ?>
                        <span class="success"><?php echo $ilang['INSTALL_STEP1_WRITABLE']; ?></span>
                        <?php
                    } else {
                        $warning = true;
                        ?>
                        <span class="warning"><?php echo $ilang['INSTALL_STEP1_LOGS_ERROR']; ?><img id="bubble3" src="resources/information.png" /></span>
                    <?php } ?>
                </td>
            </tr>
            <tr>
                <td></td>
                <td>/pages</td>
                <td>
                    <?php if ($perms['pages']) { ?>
                        <span class="success"><?php echo $ilang['INSTALL_STEP1_WRITABLE']; ?></span>
                        <?php
                    } else {
                        $fail = true;
                        ?>
                        <span class="error"><?php echo $ilang['INSTALL_STEP1_PAGES_ERROR']; ?></span>
                    <?php } ?>
                </td>
            </tr>
            <tr>
                <td></td>
                <td>/thirdparty</td>
                <td>
                    <?php if ($perms['thirdparty']) { ?>
                        <span class="success"><?php echo $ilang['INSTALL_STEP1_WRITABLE']; ?></span>
                        <?php
                    } else {
                        $warning = true;
                        ?>
                        <span class="warning"><?php echo $ilang['INSTALL_STEP1_THIRDPARTY_ERROR']; ?><img id="bubble10" src="resources/information.png" /></span>
                    <?php } ?>
                </td>
            </tr>
            <tr>
                <td></td>
                <td>/settings</td>
                <td>
                    <?php if ($perms['settings']) { ?>
                        <span class="success"><?php echo $ilang['INSTALL_STEP1_WRITABLE']; ?></span>
                        <?php
                    } else {
                        $fail = true;
                        ?>
                        <span class="error"><?php echo $ilang['INSTALL_STEP1_']; ?>Unable to write settings files.</span>
                    <?php } ?>
                </td>
            </tr>
            <tr>
                <td></td>
                <td>/uploads</td>
                <td>
                    <?php if ($perms['uploads']) { ?>
                        <span class="success"><?php echo $ilang['INSTALL_STEP1_WRITABLE']; ?></span>
                        <?php
                    } else {
                        $warning = true;
                        ?>
                        <span class="warning">
                            <?php echo $ilang['INSTALL_STEP1_UPLOADS_ERROR']; ?><img id="bubble5" src="resources/information.png" /></span>
                    <?php } ?>
                </td>
            </tr>

            <tr>
                <td colspan="2"><?php echo $ilang['INSTALL_STEP1_SYSTEM_FOLDER']; ?></td>
                <td>
                    <?php if ($perms['system']) { ?>
                        <span class="success">Found.</span>
                        <?php
                    } else {
                        $fail = true;
                        ?>
                        <span class="error"><?php echo $ilang['INSTALL_STEP1_SYSTEM_FOLDER_ERROR']; ?></span>
                    <?php } ?>
                </td>
            </tr>
            <tr>
                <td></td>
                <td>/plugins</td>
                <td>
                    <?php if ($perms['plugins']) { ?>
                        <span class="success"><?php echo $ilang['INSTALL_STEP1_WRITABLE']; ?></span>
                        <?php
                    } else {
                        $warning = true;
                        ?>
                        <span class="warning">
                            <?php echo $ilang['INSTALL_STEP1_PLUGINS_ERROR']; ?> <img id="bubble4" src="resources/information.png" />
                        </span>
                    <?php } ?>
                </td>
            </tr>
            <tr>
                <td></td>
                <td>/themes</td>
                <td>
                    <?php if ($perms['themes']) { ?>
                        <span class="success"><?php echo $ilang['INSTALL_STEP1_WRITABLE']; ?></span>
                        <?php
                    } else {
                        $warning = true;
                        ?>
                        <span class="warning">
                            <?php echo $ilang['INSTALL_STEP1_THEMES_ERROR']; ?> <img id="bubble11" src="resources/information.png" />
                        </span>
                    <?php } ?>
                </td>
            </tr>            
            <tr>
                <td colspan="2"><?php echo $ilang['INSTALL_STEP1_WEB_FOLDER']; ?></td>
                <td>
                    <?php if ($perms['web']) { ?>
                        <span class="success"><?php echo $ilang['INSTALL_STEP1_WRITABLE']; ?></span>
                        <?php
                    } else {
                        $warning = true;
                        ?>
                        <span class="warning">
                            <?php echo $ilang['INSTALL_STEP1_WEB_ERROR']; ?> <img id="bubble6" src="resources/information.png" />
                        </span>
                    <?php } ?>
                </td>
            </tr>
            <tr>
                <td colspan="2"><?php echo $ilang['INSTALL_STEP1_PHP_VERSION']; ?></td>
                <td>
                    <?php if ($version['number'] >= 5200) { ?>
                        <span class="success"><?php echo $version['name']; ?></span>
                        <?php
                    } else if ($version['number'] < 5000) {
                        $fail = true;
                        ?>
                        <span class="error"><?php echo $ilang['INSTALL_STEP1_PHP_VERSION_ERROR']; ?></span>
                        <?php
                    } else {
                        $warning = true;
                        ?>
                        <span class="warning">
                            <?php echo $ilang['INSTALL_STEP1_PHP_VERSION_WARNING']; ?><img id="bubble7" src="resources/information.png" />
                        </span>
                    <?php } ?>
                </td>
            </tr>
            <tr>
                <td colspan="2"><?php echo $ilang['INSTALL_STEP1_IMAGE_EXTENSION']; ?></td>
                <td>
                    <?php if ($gd || $imagick) { ?>
                        <span class="success"><?php echo $ilang['INSTALL_STEP1_IMAGE_EXTENSION_AVAILABLE']; ?> ( <?php echo ($gd && $imagick ? $ilang['INSTALL_STEP1_IMAGE_EXTENSION_AVAILABLE_1'] : ($gd ? $ilang['INSTALL_STEP1_IMAGE_EXTENSION_AVAILABLE_2'] : $ilang['INSTALL_STEP1_IMAGE_EXTENSION_AVAILABLE_3'])); ?>).</span>
                        <?php
                    } else {
                        $warning = true;
                        ?>
                        <span class="warning">
                            <?php echo $ilang['INSTALL_STEP1_IMAGE_EXTENSION_ERROR']; ?> <img id="bubble8" src="resources/information.png" />
                        </span>
                    <?php } ?>
                </td>
            </tr>
            <tr>
                <td colspan="2"><?php echo $ilang['INSTALL_STEP1_ZIP_EXTENSION']; ?></td>
                <td>
                    <?php if ($zip) { ?>
                        <span class="success"><?php echo $ilang['INSTALL_STEP1_ZIP_SUCCESS']; ?></span>
                        <?php
                    } else {
                        $warning = true;
                        ?>
                        <span class="warning">
                            <?php echo $ilang['INSTALL_STEP1_ZIP_ERROR']; ?> <img id="bubble9" src="resources/information.png" />
                        </span>
                    <?php } ?>
                </td>
            </tr>
        </table>
    </fieldset>
    <?php if (!$fail) { ?>
        <div>
            <span style="float: left"><a href="http://code.google.com/p/stay-simple-cms/wiki/AutomaticInstall"><?php echo $ilang['INSTALL_STEP1_INSTALLER_DOCS']; ?></a></span>
            <span style="float: right"><input type="submit" value="<?php echo $ilang['INSTALL_NEXT']; ?>" /></span>
        </div>
    <?php } ?>
    <div style="clear: both"></div>
</form>

<?php if ($fail) { ?>
    <p>
        <span class="error"><?php echo $ilang['INSTALL_STEP1_ERROR']; ?></span>
    </p
<?php } else if ($warning) { ?>
    <p>
        <span class="warning"><?php echo $ilang['INSTALL_STEP1_WARNING']; ?></span>
    </p>
<?php } else { ?>
    <p>
        <span class="success"><?php echo $ilang['INSTALL_STEP1_SUCESS']; ?></span>
    </p>
<?php } ?>